<script setup lang="ts">
import { ref } from 'vue'
import { ElMessage } from 'element-plus'

const userInfo = ref({
  username: 'user1',
  realName: '张三',
  phone: '13800138001',
  email: 'zhangsan@example.com',
  address: '北京市海淀区xxx路xxx号'
})

const isEditing = ref(false)

const saveProfile = () => {
  ElMessage.success('个人信息保存成功')
  isEditing.value = false
}

const cancelEdit = () => {
  isEditing.value = false
  ElMessage.info('已取消编辑')
}
</script>

<template>
  <div class="profile">
    <h1>个人信息</h1>
    
    <el-card>
      <template #header>
        <div class="card-header">
          <span>基本信息</span>
          <el-button v-if="!isEditing" type="primary" @click="isEditing = true">
            编辑信息
          </el-button>
        </div>
      </template>
      
      <el-form :model="userInfo" label-width="100px" :disabled="!isEditing">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="用户名">
              <el-input v-model="userInfo.username" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="真实姓名">
              <el-input v-model="userInfo.realName" />
            </el-form-item>
          </el-col>
        </el-row>
        
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="手机号码">
              <el-input v-model="userInfo.phone" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="邮箱地址">
              <el-input v-model="userInfo.email" />
            </el-form-item>
          </el-col>
        </el-row>
        
        <el-form-item label="联系地址">
          <el-input 
            v-model="userInfo.address" 
            type="textarea" 
            :rows="3"
            placeholder="请输入详细地址"
          />
        </el-form-item>
        
        <el-form-item v-if="isEditing">
          <el-button type="primary" @click="saveProfile">保存</el-button>
          <el-button @click="cancelEdit">取消</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<style scoped>
.profile {
  padding: 20px;
}

.profile h1 {
  margin-bottom: 30px;
  color: #303133;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>